<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2022/5/26
  Time: 14:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="header.jsp"%>
<html>
<head>
    <title>Title</title>
    <script src="/static/echarts/echarts.min.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .style1{
            float: left;
        }
    </style>
</head>



<body>
    <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
    <div  id="main1" style="float:left; width: 600px;height:400px;"></div>
    <div  id="main2" style="float:left; width: 600px;height:400px;"></div>

    <script type="text/javascript">
        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('main1'));
        var myChart2 = echarts.init(document.getElementById('main2'));

        $.post(
            '/echarts/getBanjiCount',
            function(jsonResult) {
                var list = jsonResult.data;
                // [{"name": "计科1班","value": 4},{"name": "计科2班","value": 3}]
                // x轴数据，存放班级名字
                // y轴数据，存放班级数量
                var xArray = new Array();
                var yArray = new Array();
                for (var i = 0; i < list.length; i++) {
                    xArray.push(list[i].name);
                    yArray.push(list[i].value);
                }
                // 指定图表的配置项和数据
                var option1 = {
                    title: {
                        text: '班级人数统计'
                    },
                    tooltip: {},
                    legend: {
                        data: ['人数']
                    },
                    xAxis: {
                        data: xArray
                    },
                    yAxis: {},
                    series: [
                        {
                            name: '销量',
                            type: 'bar',
                            data: yArray
                        }
                    ]
                };

                // 使用刚指定的配置项和数据显示图表。
                myChart1.setOption(option1);

                var option2 = {
                    title: {
                        text: '统计班级人数',
                        subtext: '',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: 'Access From',
                            type: 'pie',
                            radius: '50%',
                            data: list,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

                myChart2.setOption(option2);
            },
            'json'
        );

    </script>

</body>
</html>
